package com.douyu.test;

import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.JSON;
import com.geccocrawler.gecco.annotation.PipelineName;
import com.geccocrawler.gecco.pipeline.Pipeline;

/**
 * @Description :
 * @FileName: AloneInfoPipeline.java
 * @Author :WeiHui.Zhang
 * @Data : 2016年3月28日 上午10:07:15
 * @Version:V1.00
 */
@PipelineName(value = "aloneInfoPipeline")
public class AloneInfoPipeline implements Pipeline<AnchorInfo> {

	@Override
	public void process(AnchorInfo bean) {
		String script = bean.getScript().trim();

		int begin = script.indexOf("{\"room_id\"");
		int end = script.indexOf("widgetPosition");

		String substring = script.substring(begin, end);
		String removeEnd = StringUtils.removeEnd(substring, ",\"");
		String jsonStr = removeEnd + "}";
		
		//System.out.println(jsonStr);

		RoomScript json = JSON.parseObject(jsonStr, RoomScript.class);
		
		System.out.println(json.getOwner_uid());
		System.out.println(json.getOwner_name());
	}

}
